package r21310.chap06.d1117;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo03 {
    public static void main(String[] args) {
        List<person> list=new ArrayList<>();
        list.add(new person("刘备","蜀国"));
        list.add(new person("关羽","蜀国"));
        list.add(new person("张飞","蜀国"));
        list.add(new person("赵云","蜀国"));
        list.add(new person("曹操","魏国"));
        list.add(new person("孙权","吴国"));
    //集合的便利
                            //有条件的删除或修改  是蜀国人就留着不是蜀国人就删除


        //集合的便利
        //增强for
        /*for (person per:list) {
            System.out.print(per);
        }
        //Lambda的foreach
        list.forEach(aa->{System.out.print(aa);});*/
        //迭带器
        //创建迭代器对象
        Iterator <person>it=list.listIterator();
        while (it.hasNext()){
            person p=it.next();
            //非蜀国人 改成蜀国
            if (!p.getCountry().equals("蜀国")){p.setCountry("蜀国");}
            System.out.println(p);
        }
        //增强for

        //传统的for循环
        /*for (int i = 0; i < list.size(); i++) {
            person p=list.get(i);
            //System.out.println(p.getCountry());
            //是否为蜀国人
            if (!p.getCountry().equals("蜀国"));{list.remove(i);}
        }
        System.out.println(list);*/

    }
}